package routes

import (
    "github.com/gin-gonic/gin"
	"mars-gin/app/services"
	"mars-gin/app/middleware"
	"mars-gin/app/controllers/app"
    "net/http"
	"time"
)

// SetApiGroupRoutes 定义 api 分组路由
func SetApiGroupRoutes(router *gin.RouterGroup) {

	router.POST("/auth/register", app.Register)

	router.POST("/auth/login", app.Login)

	authRouter := router.Group("").Use(middleware.JWTAuth(services.AppGuardName))
    {
        authRouter.POST("/auth/info", app.Info)
		authRouter.POST("/auth/logout", app.Logout)
    }

	// router.POST("/user/register", func(c *gin.Context) {
    //     var form request.Register
    //     if err := c.ShouldBindJSON(&form); err != nil {
    //        c.JSON(http.StatusOK, gin.H{
    //            "error": request.GetErrorMsg(form, err),
    //        })
    //        return
    //     }
    //     c.JSON(http.StatusOK, gin.H{
    //         "message": "success",
    //     })
    // })

	router.GET("/test", func(c *gin.Context) {
		time.Sleep(5*time.Second)
		c.String(http.StatusOK, "success")
	})

    router.GET("/ping", func(c *gin.Context) {
        c.String(http.StatusOK, "pong")
    })
}